# -*- coding: utf-8 -*-

from flask_wtf import Form
from wtforms import StringField, SubmitField, PasswordField, BooleanField
from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo
from wtforms import ValidationError
from ..models import User


class LoginForm(Form):
    username = StringField('用户名', validators=[DataRequired(message='用户名不能为空')])
    password = PasswordField('密码', validators=[DataRequired(message='密码不能为空')])
    remember_me = BooleanField('记住我')
    submitField = SubmitField('登入')


class AddForm(Form):
    username = StringField('用户名', validators=[
        DataRequired('用户名不能为空'), Length(5, 10, message='用户名为5到10个字符'),
        Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, message='只能字母开头，包含字符，数字和下划线和点')])
    password = PasswordField('密码', validators=[
        DataRequired(message='密码不能为空'), EqualTo('password2', message='两次密码不一致')])
    password2 = PasswordField('确认密码', validators=[DataRequired()])
    name = StringField('真实姓名', validators=[DataRequired(message='姓名不能为空')])
    submit = SubmitField('增加')


class ChangePasswordForm(Form):
    old_password = PasswordField('旧密码', validators=[DataRequired(message='密码不能为空')])
    new_password = PasswordField('新密码',
                                 validators=[DataRequired(message='密码不能为空'),
                                             EqualTo('confirm_password', message='两次密码不一致')])
    confirm_password = PasswordField('密码确认', validators=[DataRequired()])